


def test_login(sb):
    try:
       
            # 1、登录
            sb.open("http://localhost:81/")
            sb.type("input[placeholder='账号']", "admin")
            sb.type("input[placeholder='密码']", "admin123")
            sb.type("input[placeholder='验证码']", "9568")
            sb.click("button[type='button']")
            
            
    except Exception as e:
        print(f'登录测试用例执行失败: {e}')


def test_add_experiment_after_login(sb):
    try:
      
            #2、登录成功后添加实验
            sb.wait_for_element_visible('//div[@class="el-sub-menu__title"]//span[text()="考试"]',timeout=30)
            sb.click('//div[@class="el-sub-menu__title"]//span[text()="考试"]')
            sb.click("span:contains('题库管理')")
            # sb.click("button:contains('添加实验')")
            sb.type("input[placeholder='请输入题干']", "电")
            sb.click("button:contains('搜索')")
            # sb.click("button:contains('确定')")
            # sb.assert_element("button:contains('确定')")
            
            sb.save_screenshot_to_logs()
            print(sb.get_page_title())
           
    except Exception as e:
        print(f'添加实验测试用例执行失败: {e}')


def test_add_question(self):
    try:
      
            #2、登录成功后添加实验
          
            self.click("span:contains('添加试题')")
            # sb.click("button:contains('添加实验')")
            self.type('//label[text()="题干"]/following-sibling::div//textarea', "这是输入的题干内容")
            self.click('//label[text()="试题类型"]/following-sibling::div')
            self.sleep(2)
            self.wait_for_element_visible('span[text()="判断题"]')
            element = sb.find_element('//li[.//span[text()="单选题"]]')
            self.execute_script("arguments[0].click();", element)
            # sb.click("button:contains('确定')")
            # sb.assert_element("button:contains('确定')")
            
            sb.save_screenshot_to_logs()
            print(sb.get_page_title())
            sb.sleep(10)
    except Exception as e:
        print(f'添加实验测试用例执行失败: {e}')